[ORG 0x500]
KERNEL_ADDR equ 0x1200

ARDS_TIMES_BUFFER equ 0x1100
ARDS_BUFFER equ 0x1102
ARDS_TIMES dw 0

CHECK_BUFFER_OFFSET dw 0

[SECTION .gdt]
SEG_BASE equ 0
SEG_LIMIT equ 0xfffff

VIDEO_SEG_BASE equ 0xb8000
VIDEO_SEG_LIMIT equ 0x7fff

CODE_SECTOR equ (1 << 3)
DATA_SECTOR equ (2 << 3)
VIDEO_SECTOR equ (3 << 3)

gdt_base:
    ; dummy空描述符，要求必须要有
    dd 0, 0
    ; 代码段
gdt_code:
    dw SEG_LIMIT & 0xffff
    dw SEG_BASE & 0xffff
    db SEG_BASE >> 16 & 0xff
    db 0b1001_1000
    db 0b1100_0000 | (SEG_LIMIT >> 16 & 0xf)
    db SEG_BASE >> 24 & 0xf
; 数据段
gdt_data:
    dw SEG_LIMIT & 0xffff
    dw SEG_BASE & 0xffff
    db SEG_BASE >> 16 & 0xff
    db 0b10010010
    db 0b1100_0000 | (SEG_LIMIT >> 16 & 0xf)
    db SEG_BASE >> 24 & 0xf
; 显示段
gdt_video:
    dw VIDEO_SEG_LIMIT & 0xffff
    dw VIDEO_SEG_BASE & 0xffff
    db VIDEO_SEG_BASE >> 16 & 0xff
    db 0b10010010
    db 0b01000000 | (VIDEO_SEG_LIMIT >> 16 & 0xf)
    db VIDEO_SEG_BASE >> 24 & 0xf

gdt_ptr:
    dw $ - gdt_base
    dd gdt_base

[SECTION .text]
[BITS 16]
setup_start:
    mov ax, 0
    mov ss, ax
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    
    mov si, msg
    call print
    jmp $

print:
    mov ah, 0x0e
    mov bh, 0
    mov bl, 0x01
.loop:
    mov al, [si]
    cmp al, 0
    je .done
    int 10h

    inc si
    jmp .loop
.done:
    ret

msg:
    db "hello ", 10, 13, 0